﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MS.BasicData.Infrastructure;
using MS.BasicData.Read.API.Applications.Roles;

namespace MS.BasicData.Read.API.Controllers
{
    /// <summary>
    /// 角色控制器API
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoleController : ControllerBase
    {
        private readonly IMediator _mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public RoleController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 角色信息添加
        /// </summary>
        /// <param name="create">角色信息</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiRestult> CreateRoleIfo(CreateRoleRequestModel create)
        {
            return await _mediator.Send(create);
        }

        /// <summary>
        /// 角色信息删除
        /// </summary>
        /// <param name="delete"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiRestult> DeleteRole([FromQuery]DeleteRoleRequestModel delete)
        {
            return await _mediator.Send(delete);
        }

        /// <summary>
        /// 角色信息更新
        /// </summary>
        /// <param name="update"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiRestult> UpdateRole(UpDateRoleRequestModel update)
        {
            return await _mediator.Send(update);
        }

        /// <summary>
        /// 角色信息查询
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiRestult> GetRoleAll([FromQuery]ListRoleRequestModel role)
        {
            return await _mediator.Send(role);
        }
    }
}
